# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
## NPSolitaire:
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## from PySolFC code:
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
import os

PACKAGE = 'npsolitaire'
TITLE = 'NPS Solitaire'
PACKAGE_URL = 'http://code.google.com/p/not-python-solitaire'
VERSION = 7.77

REDO = 1 | 16
UNDO = 2 | 16
UPDATE = 3 | 64


# Tk windowing system (auto set up in init.py)
WIN_SYSTEM = 'x11'                      # win32, x11, aqua, classic
USE_PY2EXE = False

# sound
# available values:
#   'pss' - PySol-Sound-Server (all)
#   'pygame' - PyGame (all)
#   'oss' (*nix)
#   'win' (windows)
#   'none' - disable
SOUND_MOD = 'auto'

# data dirs
DATA_DIRS = []
# you can add your extra directories here
if os.name == 'posix':
    DATA_DIRS = [
        '/usr/share/PySolFC',
        '/usr/local/share/PySolFC',
        '/usr/games/PySolFC',
        '/usr/local/games/PySolFC',
        ]
if os.name == 'nt':
    pass

# Set default image extensions and PIL use.
IMAGE_EXTENSIONS = [".gif", ".ppm", ".png", ".jpg", ".bmp"]

TOP_SIZE = 10
TOP_TITLE = n_('Top 10')

# use menu for select game
SELECT_GAME_MENU = True

# debug
DEBUG = 0                               # must be integer
CHECK_GAMES = False                     # check duplicated names and classes


import yaml
from collections import abc

_CONFIG_DEFAULT = ('''
animate_speed: 3
animate_flip: true
animate_redeal: true
animate_shadow: true
animate_win: true
autodeal: true
autodrop: false
autofaceup: true
bookmarks: true
cardset:
  1: [Ace of Penguins, back001.gif]
  2: [Kintengu, '']
  3: [Crystal Mahjongg, '']
  4: [Vienna 2K, '']
  5: [Hex A Deck, '']
  6: [Mughal Ganjifa, '']
  7: [Dashavatara Ganjifa, '']
  8: [Dashavatara Ganjifa, '']
  9: [Matrix, '']
  0: [Ace of Penguins, back001.gif]
colors: {cards_1: null, cards_2: null, hintarrow: null, none: null, piles: null,
         same_1: null, same_2: null, table: null, text: null}
confirm: true
demo_logo: true
drag_cursor: true
drag_shade: true
fonts:
  default: [helvetica, 12]
  fixed: [courier, 12]
  large: [helvetica, 14]
  small: [helvetica, 10]
game_fave: []
game_held: false
game_last: 2
game_recent: []
game_recent_num: 15
game_translate: true
helpbar: false
hint: true
mahjongg_create_solvable: 2
mahjongg_show_removed: false
mouse_type: drag-n-drop
mouse_undo: false
pile_bottom: false
pile_compact: true
pile_shrink: true
player: player
quickplay: true
scale_auto: false
scale_keep: true
scale: [1.0, 1.0]
mark_filled: true
mark_cards: true
mark_none: true
mark_piles: true
mark_same: true
shisen_show_hint: true
shisen_show_matching: false
shuffle: true
sound: true
sound_sample_buffer_size: 1
sound_sample_volume: 80
sound_samples: {areyousure: true, autodrop: true, autoflip: true,
  autopilotlost: true, autopilotwon: true, deal: true, dealwaste: true,
  drop: true, droppair: true, flip: true, gamefinished: false,
  gamelost: false, gameperfect: false, gamewon: false, move: true,
  nomove: true, redo: true, startdrag: true, turnwaste: true, undo: true}
splashscreen: true
statusbar: true
statusbar_seed: false
statusbar_cards: false
table_bg: Gammi.gif
timeouts: {demo: 1.0, cards: 1.0, piles: 1.0, same: 1.0, hint: 1.0,
           raise_card: 1.0}
toolbar: 1
toolbar_compound: none
toolbar_size: 0
toolbar_style: default
toolbar_vars: {autodrop: true, new: true, open: true, pause: true,
  player: true, quit: true, redo: true, restart: true, rules: true,
  save: true, shuffle: false, statistics: true, undo: true}
undo: true
update_stats: true
wm_maximized: false
wm_geometry: [1, 1]
wm_theme: default
''')


class _ConfigOptions(abc.MutableMapping):
    __data = {}
    __filename = ''

    def load(self, filename):
        self.__filename = filename
        self.__data = yaml.load(_CONFIG_DEFAULT)
        if os.path.exists(filename):
            data = None
            with open(self.__filename, mode='r') as file_:
                data = yaml.safe_load(file_)
            if data is not None:
                self.__data.update(data)

    def dump(self):
        with open(self.__filename, mode='w') as file_:
            self.__data = yaml.safe_dump(self.__data, file_)

    def __getitem__(self, key):
        if key in self.__data:
            return self.__data[key]
        raise KeyError

    def __setitem__(self, key, value):
        if key in self.__data:
            self.__data[key] = value
            return
        raise KeyError

    def __delitem__(self, key):
        if key in self.__data:
            del self.__data[key]

    def __iter__(self):
        return iter(self.__data)

    def __len__(self):
        return len(self.__data)

CONF_OPT = _ConfigOptions() #encoding='UTF8', create_empty=True)